<?xml version="1.0" encoding="utf-8" ?>
[#include "/WEB-INF/pages/common/taglibs.ftl"]
[#macro _script]
	<script type="text/javascript" src="[@c.url value='/js/custom/tables.js'/]"></script>
	<script type="text/javascript" src="[@c.url value='/js/plugins/jquery.alerts.js'/]"></script>

	<script type="text/javascript">
		var base = (function(){
			// 事件绑定
			function _addEventListeners() {
				// 维护
				$('a[act=edit]').unbind('click').click(function(){
					var	id = $(this).parent().attr('tval');
					[@c.url	var="editUrl" value='/manage/Template_edit.action' scope="page"]
						[@c.param name="type" value="${type}"/]
						[@c.param name="id" value=""/]
					[/@c.url]
					var	url	= "${editUrl}" + id;
					window.location	= url;
				})
				
				// 删除
				$('a[act=delete]').unbind('click').click(function(){
						var	id = $(this).parent().attr('tval');
						var title = $('#delete-confirm').attr('title');
						var content = $('#delete-confirm').html();
						jConfirm(content, title, function(r) {
							if (r) {
								[@c.url	var="backUrl" value='/manage/Template_list.action' scope="page"]
									[@c.param name="currentPage" value="${currentPage}"/]
									[@c.param name="type" value="${type}" /]
								[/@c.url]
								[@c.url	var="deleteUrl" value='/manage/Template_delete.action' scope="page"]
									[@c.param name="backUrl" value="${backUrl}"/]
									[@c.param name="type" value="${type}" /]
									[@c.param name="id" value=""/]
								[/@c.url]
								window.location	= "${deleteUrl}" + id;
							}
						});
					return false;
				})
			};
			function _addDateTableRender() {
				$('#dyntable').unbind().bind('sort', function (){ _addEventListeners(); })
					.dataTable( {
						"sPaginationType": "full_numbers",
					 	"oLanguage": {
						 	"sSearch": "检索：",
				            "sLengthMenu": "每页显示 _MENU_ 条记录",
				            "sZeroRecords": "未找到数据.",
				            "sInfo": "显示 _START_-_END_ 条  【共 _TOTAL_ 条】",
				            "sInfoEmpty": "显示 0-0 条 共 0 条",
				            "sInfoFiltered": "(filtered from _MAX_ total records)",
				            "oPaginate": {
				            	"sFirst": "首页",	            	
				            	"sPrevious": "上一页",
				            	"sNext": "下一页",
				            	"sLast": "末页"
				            }
				        }
					});
				//$("#dyntable_length").prepend('<button title="table1" class="deletebutton radius3" onclick="javascript:window.location=[@c.url value='/manage/Template_create.action?type=${type}' scope="page"/]">新建模板</button>&nbsp;&nbsp;');
				//增加新建模板按钮
				$("#dyntable_length").prepend('<a href="[@c.url value='/manage/Template_create.action?type=${type}' scope="page"/]" class="radius3"><span>新建模板</span></a>&nbsp;&nbsp;');	
			}
			return {
                config: {
                	url : null,
                    theme: null
                },
                init: function () {
                    _addEventListeners();
                    _addDateTableRender();
                }
			}
		}());
		
		$(function(){
			var link = "[@c.url value='/manage/Template_list.action?currentPage=${currentPage}' /]";
			base.config.theme = getTheme();
			base.config.url = link;
            //Initializing the form
			base.init();
		})
	</script>
[/#macro]

[#macro _content]
			[@demo.tableDisplayer id="templateListTable" renderTo="${renderTo}" ajaxPage="true"  property="templateList" pagesize=4 page="/manage/Template_list.action?type=${type}" name="FreemarkerTable" config="/WEB-INF/component/table/template-stdtable-autopage.ftl" bundle="messageSource"]
				[@demo.column name="id" property="ssid" title="ID" headerClass="span1" columnClass="span1 left"/]
				[@demo.column name="name" property="name" title="名称" columnClass=""/]
				[@demo.column name="path" property="path" title="路径" columnClass=""/]
				[@demo.column name="type" property="type" title="类型" columnClass=""/]
				[@demo.column name="enabled" property="enabled" format="可用:禁用" title="状态" columnClass=""/]
				[@demo.column name="operate" property="id" title="操作" columnClass="span3" innerHtml="\la href='javascript:void(0);' class='anchorbutton button_editor confirmbutton' act='edit' \g\lspan\g编辑\l/span\g\l/a\g&nbsp;|&nbsp;\la href='javascript:void(0);' class='anchorbutton button_trash confirmbutton' act='delete' \g\lspan\g删除\l/span\g\l/a\g" headerClass="batch"/]
			[/@demo.tableDisplayer]
			<div id="delete-confirm" style="display:none" title="删除模板">
				<p>模板删除后将无法恢复.您确认删除吗？</p>
			</div>

[/#macro]

[#if piece==true]
		[@_script /]
		<!--设置提交行为-->
		[#assign act="save" /]
		<!--设置table渲染到指定ID节点-->
		[#assign renderTo="#templateList"]
		[@_content /]
[#else]
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Insert title here</title>
		<meta name="menu" content="AdminMenu"/> 
		<meta name="heading" content="heading"/>
		[@_script /]
	</head>
	<body id="body">
        <div class="contenttitle radiusbottom0">
        	<h2 class="table"><span>模板列表</span></h2>
        </div><!--contenttitle-->
         <div id="templateList">[@_content /]</div>
	</body>
	</html>
[/#if]